
public class Rational implements Comparable<Rational>{
	private int numberator;
	private int denominator;
	public int getNumberator(){
		return numberator;
	}
	public void setNumberator(int num){
		this.numberator = num;
	}
	public Rational(){
		this.numberator = 0;
		this.denominator = 1;
	}
	public Rational(int num, int de){
		this.numberator =  num;
		 this.denominator = de;
 
	}
	public static int UCLN(int a, int b)
	{
		if(b==0)
			return (int)a;
		else
			return UCLN(b, a%b);
	}
	public void Reduce(Rational p){
		int uoc =  UCLN(Math.abs(p.numberator),Math.abs(p.denominator));
		int num = p.numberator/uoc;
		int de = p.denominator/uoc;
		System.out.print("\n"+ num + "/"+ de);		  
	}
	public void Reciprocal(Rational a){
		Rational p;
		if(a.numberator== 0) p = null;
		if (a.numberator < 0)
			p = new Rational(-a.denominator,-a.numberator);
		else  
			p = new Rational(a.denominator,a.numberator);
		
		Reduce(p);

	}
	public void Add(Rational p1, Rational p2){
		Rational kq;
		if (p1.denominator != p2.denominator)
		{
			kq = new Rational(p1.numberator * p2.denominator + p2.numberator * p1.denominator, p1.denominator * p2.denominator);
		}
		else
			kq = new Rational(p1.numberator + p2.numberator, p1.denominator);
		
		Reduce(kq);

	}
	public void Subtract(Rational p1, Rational p2){
		Rational kq;
		if (p1.denominator != p2.denominator)
		{
			kq = new Rational(p1.numberator * p2.denominator - p2.numberator * p1.denominator, p1.denominator * p2.denominator);
			
		}
		else
			kq = new Rational(p1.numberator - p2.numberator, p1.denominator);
		
		Reduce(kq);

	}
	public void Multiply(Rational p1, Rational p2){
		Rational kq = new Rational(p1.numberator * p2.numberator, p1.denominator*p2.denominator);
		
		Reduce(kq);
	}
	public void Divide(Rational p1, Rational p2){
		Rational kq;
		if(p2.numberator == 0)  
		{
			System.out.print("khong the chia cho khong");
			kq = null;
		}
		else 
			kq = new Rational(p1.numberator * p2.denominator,p2.numberator*p1.denominator);
		
		Reduce(kq);
	}
	
	 public int compareTo(Rational r) {
		float x = this.numberator / this.denominator;
		float y = r.numberator / r.denominator;
		float a = x - y  ; 
        if (a > 0.0001 ) {
            return -1;
        }

        if ( a < 0 && a < 0.0001 ) {
            return 1;
        }

        return 0;
	}
	public String ToString(){
		String kq = "";
        if (this.denominator != 1)
            kq = this.numberator + "/" + this.denominator;
        else kq = String.valueOf(numberator);
        return kq;
	}
	public static void main(String[] args){
		Rational a = new Rational(5,6);
		Rational b = new Rational(3,2);
		Rational c = new Rational();
		a.Reduce(a);
		c.Reciprocal(a);
		c.Add(a,b);
		c.Subtract(a, b);
		int i = b.compareTo(a);
		if (i == -1)   
			System.out.print("\n "+ a.ToString()  + " < "+b.ToString() );
		
		else if (i==1) 
			System.out.print("\n "+ a.ToString() + " > "+b.ToString() );
		else 
			System.out.print("\n "+ a.ToString() + " = "+b.ToString() );
	}

}



